package com.apotik.legenda.dao;

import java.util.ArrayList;
import java.util.List;

import javax.swing.JOptionPane;

import org.hibernate.Criteria;
import org.hibernate.classic.Session;
import org.hibernate.criterion.Order;

import com.apotik.legenda.model.Shift;
import com.apotik.legenda.util.HibernateUtil;

public class ShiftDao {

	@SuppressWarnings("unchecked")
	public List<Shift> loadAll(){
		List<Shift> list = new ArrayList<>();
		
		try {
			Session session = HibernateUtil.getSessionFactory().openSession();
			
			Criteria cr = session.createCriteria(Shift.class);
			cr.addOrder(Order.asc("shiftName"));
			
			list = cr.list();
			
			session.close();
		} catch (Exception e) {
			JOptionPane.showMessageDialog(null, e.getMessage(), "Exception", JOptionPane.ERROR_MESSAGE);
		}
		
		return list;
	}
	
}
